<?php
App::uses('AppController', 'Controller');
/**
 * SysWebsites Controller
 *
 * @property SysWebsite $SysWebsite
 * @property PaginatorComponent $Paginator
 */
class SysWebsitesController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');

/**
 * admin_index method
 *
 * @return void
 */
	public function admin_index() {
		$this->SysWebsite->recursive = 0;
		$this->set('sysWebsites', $this->Paginator->paginate());
	}

	/**
	 * function
	 * @author mingxing.zhao@qq.com
	 * @date 2013-12-22 下午1:54:42
	 * @param variable
	 * @return 
	 */
	public function admin_switch($id = null) {
		if (!$this->SysWebsite->exists($id)) {
			throw new NotFoundException(__('Invalid sys website'));
		}
		$this->Session->write('SITEID',$id);
		$this->Session->setFlash('站点已切换','tip/tip_float',array('t'=>'success'));
		$this->redirect($this->request->referer());
	}

/**
 * admin_add method
 *
 * @return void
 */
	public function admin_add() {
		if ($this->request->is('post')) {
			$this->SysWebsite->create();
			if ($this->SysWebsite->save($this->request->data)) {
				$this->Session->setFlash(__('The sys website has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The sys website could not be saved. Please, try again.'));
			}
		}
		$sysCities = $this->SysWebsite->SysCity->find('list');
		$sysAreas = $this->SysWebsite->SysArea->find('list');
		$this->set(compact('sysCities', 'sysAreas'));
	}

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		if (!$this->SysWebsite->exists($id)) {
			throw new NotFoundException(__('Invalid sys website'));
		}
		if ($this->request->is(array('post', 'put'))) {
			if ($this->SysWebsite->save($this->request->data)) {
				$this->Session->setFlash(__('The sys website has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The sys website could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('SysWebsite.' . $this->SysWebsite->primaryKey => $id));
			$this->request->data = $this->SysWebsite->find('first', $options);
		}
		$sysCities = $this->SysWebsite->SysCity->find('list');
		$sysAreas = $this->SysWebsite->SysArea->find('list');
		$this->set(compact('sysCities', 'sysAreas'));
	}

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		$this->SysWebsite->id = $id;
		if (!$this->SysWebsite->exists()) {
			throw new NotFoundException(__('Invalid sys website'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->SysWebsite->delete()) {
			$this->Session->setFlash(__('The sys website has been deleted.'));
		} else {
			$this->Session->setFlash(__('The sys website could not be deleted. Please, try again.'));
		}
		return $this->redirect(array('action' => 'index'));
	}}
